package top.wardyan.wbaseswt.util;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;

public class Msg {
	
	/**
	 * 显示提示框 <p>2020-01-28 16:15:49 决定逐渐废弃</p>
	 * @param title
	 * @param msg
	 */
	public static void showMessage(String title, String msg) {
		Shell parent = Display.getCurrent().getActiveShell();
		Boolean xNeedDispose = false;
		if(parent == null) {
			parent = new Shell();
			xNeedDispose = true;
		}
		MessageBox msgbox = new MessageBox(parent, SWT.NONE);
		msgbox.setText(title);
		msgbox.setMessage(msg);
		msgbox.open();
		
		msgbox = null;
		if(xNeedDispose) {
			parent.dispose();
		}
	}
	
	public static void show(String title, String msg) {
		Shell parent = Display.getCurrent().getActiveShell();
		Boolean needDispose = false;
		if(parent == null) {
			parent = new Shell();
			needDispose = true;
		}
		show(parent, title, msg);
		if(needDispose) {
			parent.dispose();
		}
	}
	
	public static void show(Shell parent, String title, String msg) {
		MessageBox msgbox = new MessageBox(parent, SWT.NONE);
		msgbox.setText(title);
		msgbox.setMessage(msg);
		msgbox.open();
	}
	
	public static void error(Shell parent, String msg) {
		show(parent, "错误", msg);
	}
	
	public static int confirm(Shell parent, String title, String msg, int btns) {
		MessageBox msgbox = new MessageBox(parent, btns);
		msgbox.setText(title);
		msgbox.setMessage(msg);
		return msgbox.open();
	}

}
